import Vue from 'vue'
import lineComponent from './index.vue'

let lineConstructor = Vue.extend(lineComponent)

let instance;

const Line = (options = {}) => {
  // 判断是否已存在实例
  if (!document.getElementById('LineWin')) {
    // 初始化实例，此时instance是一个组件实例，但未初始化未完成
    instance = new lineConstructor({
      data: options
    });

    // 完成初始化
    instance.$mount();

    // 将组件添加到根节点body
    document.body.appendChild(instance.$el);
  }
}

Line.open = (data, backFun) => {
  Line()
  console.log('data',data);
  if (data.lineId) {
    instance.title = "编辑路线";
  } else {
    instance.title = "添加路线";
  }
  instance.lineId = data.lineId;
  instance.townShipList = data.townShipList;
  instance.routeTopicList = data.routeTopicList;
  instance.backFun = backFun;
  instance.timeStamp = new Date().getTime();
  instance.visible = true;

}


Line.close = () => {
  Line()
  instance.visible = false;
}

export default Line
